<template>
    <view class="container">
        <view class="box">
            <!-- #ifdef MP -->
            <view class="login-wx">
                <view class="business">
                    <text>{{ shopName }}</text>
                </view>
                <view class="apply-tip">
                    <text class="apply-tip-title">申请获得以下权限</text>
                    <text class="apply-tip-desc">获取您的公开信息（昵称、头像，地区）等</text>
                </view>
                <button class="btn btn-success btn-save" @click="authorizeFn">授权登录</button>
            </view>
            <!-- #endif -->
        </view>
    </view>
</template>

<script>
import cardCellInput from "@/pages_supplier/components/common/cell/card-cell-input.vue"
import storage from "@/uni-sub-base/utils/storage.js"
import { getUserCarList } from "@/utils/cartUtil.js"
import config from "@/config/config.js"
import { mobileLogin } from "@/pages_supplier/service/api/user.js"
import { getMiniProgramOpenId } from "@/pages_supplier/service/api/weChat.js"
import { registerByWeixin, RegisterAndLogin } from "@/pages_supplier/service/api/authorize.js"
import { AddLoginAuthApply } from "@/pages_supplier/service/api/loginAuth.js"
import webViewUrl from "@/pages/micro/webViewUrl.js"
import { getLocation } from "@/uni-sub-base/utils/mapUtil.js"
export default {
    components: {
        cardCellInput,
    },
    data() {
        return {
            sessionKey: "",
            openId: "",
            nickName: null,
            avatarUrl: null,
            userInfo: {},
            data: "",
            isShow: false,
            url: "",
            showNav: false,
            location: null,
            userData: null,
            shopName: "",
        }
    },
    onLoad(e) {},
    mounted() {
        this.shopName = this.getAppSet().shopName
    },
    methods: {
        authorizeFn() {
            uni.getUserProfile({
                desc: "登录",
                success: (res) => {
                    this.userData = res
                    this.data = JSON.stringify(res)
                    this.login()
                },
                fail: (res) => {
                    console.log(res)
                },
            })
        },
        //登录
        login() {
            let that = this
            // 获取登录用户code
            uni.login({
                provider: "weixin",
                success: function (res) {
                    if (res.code) {
                        let code = res.code
                        console.log(res.code)
                        that.getOpenApi(res)
                    } else {
                        uni.showToast({
                            title: "登录失败！",
                            duration: 2000,
                        })
                        console.log("登录失败！" + res.errMsg)
                    }
                },
            })
        },
        //微信登录接口
        getOpenApi(data) {
            let webInfo = storage.getCache("webInfo")
            let param = {
                code: data.code,
                businessId: webInfo.BusinessId,
                accId: webInfo.WxAccountId,
            }
            let path = "?code=" + data.code
            getMiniProgramOpenId(param, path).then((res) => {
                if (res.Data) {
                    let open_id = res.Data.OpenId
                    storage.setCache("openId", open_id)
                    this.$emit("tipclose")
                }
            })
        },
    },
}
</script>

<style lang="scss">
page {
    background: $color-white;
}

.container {
    padding: $app-page-padding;
}

.login-wx {
    .business {
        display: flex;
        justify-content: center;
        border-bottom: solid 1rpx #cdcdcd;
        margin-bottom: 48rpx;
        padding-bottom: 48rpx;

        text {
            font-size: $font-size-44;
        }
    }

    .apply-tip {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;

        .apply-tip-title {
            color: $color-black;
            font-size: $font-size-32;
            margin-bottom: 36rpx;
        }

        .apply-tip-desc {
            color: $app-color-text-desc;
            font-size: $font-size-26;
        }

        margin-bottom: 80rpx;
    }

    .btn {
        height: 80rpx;
        border-radius: 100rpx;
    }
}

.webView-mark {
    width: 100vw;
    height: 100vh;
    background: #fff;
    position: fixed;
    z-index: 999999999999;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
}

.webView-mark-load-text {
    margin-top: 300rpx;
}
</style>
